#!/bin/sh
. $HOME/.config/defaultprograms.txt

case "$1" in
 -default)
 echo $BROWSER > $HOME/.config/tmp/browser
 
 programchooser $BROWSER internet-web-browser "WebBrowser" None > $HOME/.config/tmp/webbrowser
 cat $HOME/.config/defaultprograms.txt | grep -v BROWSER > $HOME/.config/defaultprograms.new
 BROWSER="`cat $HOME/.config/tmp/webbrowser`"
 [ "$BROWSER" = "" ] && BROWSER="cat $HOME/.config/tmp/browser"
 echo BROWSER=\"$BROWSER\" >> $HOME/.config/defaultprograms.new
 mv -f $HOME/.config/defaultprograms.new $HOME/.config/defaultprograms.txt
 rm -f $HOME/.config/tmp/browser
 rm -f $HOME/.config/tmp/webbrowser
 ;;
 *)
 exec $BROWSER "$@"
 ;;
esac
